home *** CD-ROM | disk | FTP | other *** search
- #include "Intuition_utils.h"
- #include <proto/all.h>
-
- #define DONT_KNOW -2
-
- #define FIRST_V2_LIB 36
-
- BOOL is_Workbench_v2( void )
- /* returns TRUE if you're running Workbench 2.0 */
- {
- static BOOL is_Wb2 = DONT_KNOW;
- struct Library *lib;
-
- if (DONT_KNOW == is_Wb2)
- {
- if (lib = OpenLibrary( "intuition.library", FIRST_V2_LIB ))
- {
- is_Wb2 = TRUE;
- CloseLibrary(lib);
- }
- else
- is_Wb2 = FALSE;
- }
-
- return (BOOL) is_Wb2;
- }
-
-
- void GadgetRelativeCoords( struct Gadget *gadget,
- struct IntuiMessage *event,
- Point *point )
- {
- struct Window *window;
-
- window = event->IDCMPWindow;
-
- point->x = event->MouseX - gadget->LeftEdge;
- point->y = event->MouseY - gadget->TopEdge;
-
- if (window->Flags & GIMMEZEROZERO)
- {
- point->x -= window->BorderLeft;
- point->y -= window->BorderTop;
- }
-
- }
-
-
-
- static USHORT __chip BusyPointerData[] =
- {
- 0x0000,0x0000,
- 0x0400,0x07C0,0x0000,0x07C0,0x0100,0x0380,0x0000,0x07E0,
- 0x07C0,0x1FF8,0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
- 0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,0x3FF8,0x7FFE,
- 0x3FF8,0x7FFE,0x1FF0,0x3FFC,0x07C0,0x1FF8,0x0000,0x07E0,
- 0x0000,0x0000,
- };
-
-
- void SetWaitPointer( struct Window *w )
- {
- SetPointer(w, BusyPointerData, 16, 16, -6, 0);
- }
-
-
-
- struct IntuiMessage *WaitForMessage( struct MsgPort *mport )
- {
- struct IntuiMessage *imsg;
-
- for(;;)
- {
- imsg = (struct IntuiMessage*) GetMsg(mport);
- if (imsg) return imsg;
-
- WaitPort(mport);
- }
- }
-
- struct Window *OpenWindowWithSharedUserPort( struct NewWindow *nw,
- struct MsgPort *shared )
- {
- ULONG IDCMPbuf;
- struct Window *w;
-
- IDCMPbuf = nw->IDCMPFlags;
- nw->IDCMPFlags = 0; /* no IDCMP flags. */
-
- if (w = OpenWindow( nw ))
- {
- w->UserPort = shared; /* assign UserPort. */
- ModifyIDCMP( w, IDCMPbuf ); /* turn on IDCMP */
- }
- nw->IDCMPFlags = IDCMPbuf; /* return 'nw' to its previous state. */
- return w;
- }
-
-
- void StripIntuiMessages( struct Window *w )
- /*
- *ASSUMES* a Forbid() has been called!
-
- Taken from 1.3 RKM:L&D, page 171
- */
- {
- struct MsgPort *mp;
- struct IntuiMessage *msg, *succ;
-
- mp = w->UserPort;
-
- /*
- * Loop through all messages waiting at this port, remove any
- * which are for Window 'w'.
- */
-
- msg = (struct IntuiMessage*) mp->mp_MsgList.lh_Head;
- while( succ = (struct IntuiMessage*) msg->ExecMessage.mn_Node.ln_Succ )
- {
- if (msg->IDCMPWindow == w)
- {
- Remove((struct Node *) msg);
- ReplyMsg((struct Message *) msg);
- }
-
- msg = succ;
- }
- }
-
- void CloseWindowWithSharedUserPort( struct Window *w )
- /* Taken from 1.3 RKM:L&D, page 171, 'CloseWindowSafely()' */
- {
- Forbid(); /* Turn off multitasking */
-
- StripIntuiMessages( w ); /* remove all messages for this window. */
-
- w->UserPort = NULL;
- ModifyIDCMP( w, 0 ); /* prevents new messages from occuring. */
- Permit();
-
- CloseWindow( w );
- }
-
-
- BOOL WindowSanityCheck( struct Screen *screen,
- Point *location,
- Point *size )
- /* returns FALSE if location or size was changed. */
- {
- BOOL ok = TRUE;
-
-
- if (size->x > screen->Width)
- {
- ok = FALSE;
- size->x = screen->Width;
- }
-
- if (size->y > screen->Height )
- {
- ok = FALSE;
- size->y = screen->Height;
- }
-
- /* size is now ok, so check location. */
- if (location->x + size->x >= screen->Width)
- {
- location->x = screen->Width - size->x;
- ok = FALSE;
- }
- if (location->y + size->y >= screen->Height)
- {
- location->y = screen->Height - size->y;
- ok = FALSE;
- }
-
- return ok;
- }
-
- #include <utility/tagitem.h>
-
- UWORD minimal_pens [1] = { ~0 };
-
- struct TagItem screen_tags[] =
- {
- { SA_Pens, (ULONG) minimal_pens },
- { TAG_END, 0 }
- };
-
- struct Screen *SmartOpenScreen( struct NewScreen *newscreen )
- {
- if (is_Workbench_v2())
- {
- return OpenScreenTagList( newscreen, screen_tags );
- }
- else
- return OpenScreen( newscreen );
- }
-
-
- void RemapImage( struct Image *image )
- {
- UWORD *plane1, *plane2, temp;
- short i, planesize;
-
- planesize = ((image->Width+15)/16) * image->Height;
-
- plane1 = &image->ImageData[0];
- plane2 = &image->ImageData[planesize];
- for (i=0; i<planesize; i++)
- {
- temp = plane1[i];
- plane1[i] = plane2[i];
- plane2[i] = temp;
- }
- }